package com.yimu.lib.http.net;

import android.text.TextUtils;

/**
 * 描述：TODO
 * 创建者：  Churck
 * 创建时间：2017/4/27 13:24
 * 修改者： Churck
 * 修改时间：2017/4/27 13:24
 * 版 本：v1.0
 */

public class HttpRequest implements HttpListener {
    private HttpCallback callback;
    public HttpRequest() {
    }
    public HttpRequest(HttpCallback callback) {
        this.callback=callback;
    }
    public void setCallback(HttpCallback callback) {
        this.callback = callback;
    }
    @Override
    public void start() {

        if (null!=callback){
            callback.start();
        }

    }

    @Override
    public void update(int progress) {

    }

    @Override
    public Object doInBackground(Object o) {

        if (o instanceof NetFuntion){
            NetFuntion netFuntion= (NetFuntion) o;
           String result= netFuntion.doRequestHttp();
            if (TextUtils.isEmpty(netFuntion.getNetwrodStr())){
                return result;
            }else {
                return netFuntion;
            }

        }
        return null;
    }

    @Override
    public void result(Object o) {
        if (null!=callback){
            if (o instanceof String){
                callback.onSucceed(o);
            }else if (o instanceof NetFuntion){
                callback.onFailed(((NetFuntion) o).getNetwrodStr());
            }
        }


    }


}
